﻿using Command.CommunityToolkit.Attributes;
using Command.CommunityToolkit.Helpers;
using Command.CommunityToolkit.Services;

namespace Command.CommunityToolkit.Commands.Impl;

[Command("default")]
public class DefaultCommand : CommandBase
{
    public DefaultCommand(object args, IQualityControl qualityControl) : base(args, qualityControl)
    {
    }

    public override string Summary() => "验证指定卷标名称下的证书压缩文件";

    public override string Description() =>
        @"
ezqc
不带参数执行命令，则会读取卷标为PoiLicenses的存储，并解压所有后缀为.zip的文件，以默认UTF-8编码格式读取内容到内存，进行软件激活；
";
    public override string[] GetLicenses()
    {
        var serviceProvider = ServiceProviderHelper.GetInstance().ServiceProvider;
        if (serviceProvider == null) throw new Exception("serviceProvider初始化异常");
        var configurationManager = serviceProvider.GetService<ConfigurationManager>();
        var vlabel = configurationManager?["VolumeLabel"];
        if (string.IsNullOrWhiteSpace(vlabel)) throw new ArgumentNullException($"没有找到VolumeLabel配置");
#if DEBUG
        var files = Directory.GetFiles(@"C:\demo", "*.zip");
#endif


#if !DEBUG
            DriveInfo? driveInfo = DriveInfo.GetDrives().FirstOrDefault(d => d.IsReady && Equals(d.VolumeLabel.ToUpper(), vlabel.ToUpper()));
            if (driveInfo == null) throw new Exception($"请确保存在名为{vlabel}的存储，且存储运行正常。");
            var files = Directory.GetFiles(driveInfo.Name, "*.zip");
#endif

        return files;
    }
}